package com.ylr.blog.framework.service.impl;

import com.ylr.blog.framework.service.BlogContentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ylr.blog.framework.mapper.BlogContentMapper;
import com.ylr.blog.framework.entity.BlogContentEntity;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-05-23 22:23:59
 * className: BlogContentServiceImpl
 * version: 1.0
 * description:
 */
@Service("blogContentService")
public class BlogContentServiceImpl extends ServiceImpl<BlogContentMapper, BlogContentEntity> implements BlogContentService {

    private static final Logger log = LoggerFactory.getLogger(BlogContentServiceImpl.class);

    @Override
    public void saveBlogContent(Long blogId, String content) {
        BlogContentEntity blogContent = new BlogContentEntity();
        blogContent.setBlogId(blogId)
                .setContent(Optional.ofNullable(content).orElse(StringUtils.EMPTY));
        // 保存数据
        baseMapper.insert(blogContent);
        log.info("博客正文内容保存完成");
    }

    @Override
    public String getContent(Long blogId) {
        return baseMapper.selectContent(blogId);
    }

    @Override
    public void updateBlogContent(Long blogId, String content) {
        BlogContentEntity blogContent = new BlogContentEntity();
        blogContent.setBlogId(blogId)
                .setContent(Optional.ofNullable(content).orElse(StringUtils.EMPTY));
        // 保存数据
        int count = baseMapper.updateById(blogContent);
        log.info("博客正文内容修改完成。count={}", count);
    }

    @Override
    public void deleteBlogContent(Long blogId) {
        int count = baseMapper.deleteById(blogId);
        log.info("博客正文内容删除完成。blogId={} count={}", blogId, count);
    }

    @Override
    public void removeBlogContent(List<Long> blogIdList) {
        int count = baseMapper.deleteBatchIds(blogIdList);
        log.info("博客正文内容删除完成。count={}", count);
    }
}